package com.gujiangbo.chapter09;

import org.junit.Test;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/4/7 19:10
 * @Version: 1.0
 * @Description:
 */
public class JavaString {

    @Test
    public void test01() {
        String s1 = "a" + "b" + "c";// 常量与常量的拼接结果在常量池，原理是编译期优化
        String s2 = "abc";
        System.out.println(s1 == s2);//true
        System.out.println(s1.equals(s2));//true
    }

    @Test
    public void test02() {
        final String s1 = "a";
        final String s2 = "b";
        String s3 = "ab";
        String s4 = s1 + s2;
        System.out.println(s3 == s4);//true

    }

    @Test
    public void test03() {
        String s1 = "javaHadoop";
        String s2 = "java";
        String s3 = (s2 + "Hadoop").intern();
        System.out.println(s3 == s1);//true
        final String s4 = "java";
        String s5 = s4 + "Hadoop";
        System.out.println(s1 == s5);//true
    }
}
